package com.lagou.service.impl;

import com.lagou.base.StatusCode;
import com.lagou.dao.CourseContentDao;
import com.lagou.dao.impl.CourseContentDapImpl;
import com.lagou.pojo.Course;
import com.lagou.pojo.Course_Lesson;
import com.lagou.pojo.Course_Section;
import com.lagou.service.CourseContentService;
import com.lagou.utils.DateUtils;

import java.util.List;

/**
 * 课程内容管理service接口实现类
 */
public class CourseContentServiceImpl implements CourseContentService {
    CourseContentDao courseContentDao = new CourseContentDapImpl();
    @Override
    public List<Course_Section> findSectionAndLessonByCourseId(int courseId) {
        return courseContentDao.findSectionAndLessonByCourseId(courseId);
    }

    @Override
    public Course findCourseByCOurseId(int courseId) {
        return courseContentDao.findCourseByCourseId(courseId);
    }

    @Override
    public String saveSection(Course_Section section) {
        section.setStatus(2);
        String dateFormart = DateUtils.getDateFormart();
        section.setCreate_time(dateFormart);
        section.setUpdate_time(dateFormart);
        int update = courseContentDao.saveSection(section);
        if(update == 1){
            return StatusCode.SUCCESS.toString();
        }else{
            return StatusCode.FAIL.toString();
        }
    }

    @Override
    public String updateSection(Course_Section section) {
        String dateFormart = DateUtils.getDateFormart();
        section.setUpdate_time(dateFormart);
        int i = courseContentDao.updateSection(section);
        if(i == 1){
           return StatusCode.SUCCESS.toString();
        }else{
            return StatusCode.FAIL.toString();
        }
    }
    @Override
    public String updateSectionStatus(int id, int status) {
        int update = courseContentDao.updateSectionStatus(id, status);
        if(update == 1){
            return StatusCode.SUCCESS.toString();
        }else {
            return StatusCode.FAIL.toString();
        }
    }
    //保存课时方法
    @Override
    public String saveLesson(Course_Lesson lesson) {
        int update = courseContentDao.saveLesson(lesson);
        if(update == 1){
            return StatusCode.SUCCESS.toString();
        }else{
            return StatusCode.FAIL.toString();
        }
    }
    //更新课时方法
    @Override
    public String updateLesson(Course_Lesson lesson) {
        int update = courseContentDao.updateLesson(lesson);
        if(update == 1){
            return StatusCode.SUCCESS.toString();
        }else{
            return StatusCode.FAIL.toString();
        }
    }
}
